package com.webcams.core.utils;

import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;

import com.webcams.core.resorts.DownloadListener;

public class AsyncLoadBitmap extends AsyncTask<String, Integer, Bitmap> {

	private DownloadListener listener;
	private ProgressDialog progress;

	public AsyncLoadBitmap(DownloadListener listener) {
		this.listener = listener;
	}

	@Override
	protected Bitmap doInBackground(String... urls) {
		return BitmapFactory.decodeFile(urls[0]);
	}

	@Override
	protected void onProgressUpdate(Integer... _progress) {
		if(progress != null) {
			progress.setProgress(_progress[0]);
		}
	}
	
	protected void onPostExecute(Bitmap result) {
		if(progress != null) {
			progress.dismiss();
		}
		listener.imageFinishedLoad(result);
	}

	public void setProgressDialog(ProgressDialog progressDialog) {
		this.progress = progressDialog;
	}
}
